package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: bjc
 * Date: 2025-08-14
 * Time: 21:25
 */
public class ThreadDemo8 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            System.out.println("线程代码");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        //t.setDaemon( true);//设置为守护线程
        //start之前，检查isAlive
        System.out.println("start开始之前:"+t.isAlive());
        t.start();
        //start之后，检查isAlive
        System.out.println("start开始之后:"+t.isAlive());
        //保证线程t执行结束
        Thread.sleep(2000);
        System.out.println("t线程结束后："+t.isAlive());
    }
}
